package com.txunda.zhuohired.adapter.user.home;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.aty.user.home.PartJobDetailsAty;
import com.txunda.zhuohired.bean.user.home.ReruitBean;

import java.util.ArrayList;


/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/2/27 9:18
 * 功能描述：兼职计划adapter
 * 联系方式：jiahuanchen@126.com
 */

public class PartTimeAdapter extends BaseAdapter {

    private Context context;
    private ViewHolder holder;
    private ArrayList<ReruitBean.DataBean> reruitBeanList;

    public PartTimeAdapter(Context context, ArrayList<ReruitBean.DataBean> reruitBeanList) {
        this.context = context;
        this.reruitBeanList = reruitBeanList;
    }

    @Override
    public int getCount() {
        return reruitBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return reruitBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_part_time, null);
            holder = new ViewHolder();
            view.setTag(holder);
            ViewUtils.inject(holder, view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        Glide.with(context).load(reruitBeanList.get(i).getLogo()).error(R.mipmap.icon_defult).placeholder(R.mipmap
                .icon_defult).dontAnimate().into(holder.iv_item_part_time);
        if ("1".equals(reruitBeanList.get(i).getPart_status())) {
            holder.tv_item_part_time_type.setVisibility(View.VISIBLE);
            holder.tv_item_part_time_type.setText("日结");
            holder.tv_item_part_time_type.setBackgroundResource(R.drawable.shape_part_blue);
            holder.tv_item_part_time_type.setTextColor(context.getResources().getColor(R.color.blue));
        } else if ("2".equals(reruitBeanList.get(i).getPart_status())) {
            holder.tv_item_part_time_type.setVisibility(View.VISIBLE);
            holder.tv_item_part_time_type.setText("月结");
            holder.tv_item_part_time_type.setTextColor(context.getResources().getColor(R.color.yellow));
            holder.tv_item_part_time_type.setBackgroundResource(R.drawable.shape_part_yellow);
        } else {
            holder.tv_item_part_time_type.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(reruitBeanList.get(i).getTitle())) {
            holder.tv_item_part_time_name.setVisibility(View.INVISIBLE);
        } else {
            holder.tv_item_part_time_name.setVisibility(View.VISIBLE);
            holder.tv_item_part_time_name.setText(reruitBeanList.get(i).getTitle());
        }
        if (TextUtils.isEmpty(reruitBeanList.get(i).getPart_datestart()) && TextUtils.isEmpty(reruitBeanList.get(i)
                .getPart_dateend())) {
            holder.tv_item_part_time_time.setVisibility(View.GONE);
        } else {
            holder.tv_item_part_time_time.setVisibility(View.VISIBLE);
            holder.tv_item_part_time_time.setText(reruitBeanList.get(i).getPart_datestart() + "-" + reruitBeanList
                    .get(i).getPart_dateend());
        }
        if (TextUtils.isEmpty(reruitBeanList.get(i).getName())) {
            holder.tv_item_part_time_company.setVisibility(View.INVISIBLE);
        } else {
            holder.tv_item_part_time_company.setVisibility(View.VISIBLE);
            holder.tv_item_part_time_company.setText(reruitBeanList.get(i).getName());
        }
        if (TextUtils.isEmpty(reruitBeanList.get(i).getPrice())) {
            holder.tv_item_part_time_pay.setVisibility(View.INVISIBLE);
        } else {
            holder.tv_item_part_time_pay.setVisibility(View.VISIBLE);
            holder.tv_item_part_time_pay.setText(reruitBeanList.get(i).getPrice() + "元");
        }
        holder.ll_item_part_time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, PartJobDetailsAty.class);
                intent.putExtra("part_details_id", reruitBeanList.get(i).getId());
                context.startActivity(intent);
            }
        });
        return view;
    }

    class ViewHolder {
        @ViewInject(R.id.ll_item_part_time)
        private LinearLayout ll_item_part_time;
        /**
         * logo
         */
        @ViewInject(R.id.iv_item_part_time)
        private ImageView iv_item_part_time;
        /**
         * 结算方式
         */
        @ViewInject(R.id.tv_item_part_time_type)
        private TextView tv_item_part_time_type;
        /**
         * 标题
         */
        @ViewInject(R.id.tv_item_part_time_name)
        private TextView tv_item_part_time_name;
        /**
         * 时间
         */
        @ViewInject(R.id.tv_item_part_time_time)
        private TextView tv_item_part_time_time;
        /**
         * 公司名称
         */
        @ViewInject(R.id.tv_item_part_time_company)
        private TextView tv_item_part_time_company;
        /**
         * 价格
         */
        @ViewInject(R.id.tv_item_part_time_pay)
        private TextView tv_item_part_time_pay;
    }
}
